﻿<UserControl x:Class="Freshome.m.vws.Recipes"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:f="clr-namespace:Freshome.m.vws">
    <UserControl.Resources>
        <f:Bool2Visible x:Key="b2v" />
    </UserControl.Resources>
    <Grid x:Name="topanel">
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="200" Width="2*"></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition MinWidth="100" Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <DataGrid x:Name="dgr" ItemsSource="{Binding Path=P_rps}" IsReadOnly="{Binding Readonly}" Grid.Row="0" Grid.Column="0">
            <DataGrid.CommandBindings>
                <CommandBinding Command="ApplicationCommands.Open" CanExecute="Recipe_CanExecute" Executed="OpenImage_Executed" />
                <CommandBinding Command="ApplicationCommands.Delete" CanExecute="Recipe_CanExecute" Executed="Delete_Executed" />
                <CommandBinding Command="ApplicationCommands.Find" CanExecute="Find_CanExecuted" Executed="Find_Executed" />
            </DataGrid.CommandBindings>
            <DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Border Margin="2" BorderThickness="1" BorderBrush="SteelBlue" CornerRadius="3" Width="200" Height="150" HorizontalAlignment="Left">
                            <Border.Background>
                                <ImageBrush ImageSource="{Binding Path=Bimage}" Stretch="None"></ImageBrush>
                            </Border.Background>
                        </Border>
                        <StackPanel>
                            <TextBlock><Hyperlink Command="ApplicationCommands.Open">换图片</Hyperlink></TextBlock>
                            <TextBlock><Hyperlink Command="ApplicationCommands.Find" CommandParameter="{Binding Path=Raw.Mid}">配料单</Hyperlink></TextBlock>
                        </StackPanel>    
                    </StackPanel>
                </DataTemplate>
            </DataGrid.RowDetailsTemplate>
            <DataGrid.ContextMenu>
                <ContextMenu Visibility="{Binding Path=Enabled, Converter={StaticResource b2v}}">
                    <MenuItem Header="删食谱" Command="ApplicationCommands.Delete"></MenuItem>
                </ContextMenu>
            </DataGrid.ContextMenu>
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Path=Name}" Header="食谱名称"
                                    MinWidth="100" MaxWidth="200" ToolTipService.ToolTip="2 - 10个字符"/>
                <DataGridCheckBoxColumn x:Name="cbRecipe" Binding="{Binding Path=MeatRiceFarciHot}" MinWidth="20" MaxWidth="30">
                </DataGridCheckBoxColumn>
                <DataGridTextColumn Binding="{Binding Path=Notes}" Header="食谱说明" 
                                    MinWidth="100" MaxWidth="500" ToolTipService.ToolTip="0 - 50个字符"/>
                <DataGridCheckBoxColumn Binding="{Binding Path=Spring}" Header="春" MinWidth="20" MaxWidth="30"></DataGridCheckBoxColumn>
                <DataGridCheckBoxColumn Binding="{Binding Path=Summer}" Header="夏" MinWidth="20" MaxWidth="30"></DataGridCheckBoxColumn>
                <DataGridCheckBoxColumn Binding="{Binding Path=Autumn}" Header="秋" MinWidth="20" MaxWidth="30"></DataGridCheckBoxColumn>
                <DataGridCheckBoxColumn Binding="{Binding Path=Winter}" Header="冬" MinWidth="20" MaxWidth="30"></DataGridCheckBoxColumn>
            </DataGrid.Columns>
        </DataGrid>
        <TextBlock Grid.Row="1" Grid.Column="0">图片文件不能超过32K字节，建议使用160x120像素的图片。</TextBlock>
        <GridSplitter Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Width="3" VerticalAlignment="Stretch" HorizontalAlignment="Center" ShowsPreview="True"></GridSplitter>
        <DataGrid x:Name="dgp" Grid.Row="0" Grid.Column="2" ItemsSource="{Binding ElementName=dgr, Path=SelectedItem.Steps}" KeyDown="dgp_KeyDown" IsReadOnly="{Binding Readonly}">
            <DataGrid.CommandBindings>
                <CommandBinding Command="ApplicationCommands.Delete" CanExecute="Steplan_CanExecute" Executed="Delete_Executed" />
            </DataGrid.CommandBindings>
            <DataGrid.ContextMenu>
                <ContextMenu Visibility="{Binding Path=Enabled, Converter={StaticResource b2v}}">
                    <MenuItem Header="删制作" Command="ApplicationCommands.Delete"></MenuItem>
                </ContextMenu>
            </DataGrid.ContextMenu>
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Path=Planum}" Header="序号"
                                    MinWidth="30" MaxWidth="50" ToolTipService.ToolTip="数字：0 - 255"/>
                <DataGridTextColumn Binding="{Binding Path=Notes}" Header="制作过程" 
                                    MinWidth="100" MaxWidth="500" ToolTipService.ToolTip="0 - 50个字符"/>
            </DataGrid.Columns>
        </DataGrid>
        <Button Grid.Row="1" Grid.Column="2" Visibility="{Binding Path=Enabled, Converter={StaticResource b2v}}"
                Command="{Binding Path=Save}" Content="{Binding Path=Save.Name}" HorizontalAlignment="Right"></Button>
    </Grid>
</UserControl>
